package com.sz.biz.logistics.ord.service.impl;

import com.sz.biz.common.constants.ModuleNames;
import com.sz.common.base.constants.UserActions;
import com.sz.common.base.dao.ParamData;
import com.sz.common.base.service.AbstractService;
import com.sz.biz.logistics.ord.entity.OrdOrderServiceLwh;
import com.sz.biz.logistics.ord.service.OrdOrderServiceLwhService;
import com.sz.common.core.service.PrincipalLogUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

import java.util.*;

/**
 * Package: com.sz.biz.logistics.ord.service.impl <br>
 * <p>
 * Function: 服务商称重的长宽高，暂时不用 <br>
 * Author: hpeng.wang. <br>
 * Date: 2017-04-25 21:03:00.
 */
@Service
public class OrdOrderServiceLwhServiceImpl extends AbstractService implements OrdOrderServiceLwhService {
    @Override
    protected String getMapperNamespace() {
        return "com.sz.biz.logistics.ord.entity.OrdOrderServiceLwhMapper";
    }

    @Override
    public void save(OrdOrderServiceLwh ordOrderServiceLwh) {
        if (!ObjectUtils.isEmpty(ordOrderServiceLwh)) {
            this.batchSave(Arrays.asList(ordOrderServiceLwh));
        }

    }

    @Override
    public void batchSave(List<OrdOrderServiceLwh> orderServiceLwhList) {
        if (!CollectionUtils.isEmpty(orderServiceLwhList)) {
            dao.batchInsert(getSqlName("insertSelective"), orderServiceLwhList);
            //操作日志
            Map<String, Object> dataBackup = new HashMap<>();
            dataBackup.put("ADD_ORD_ORDER_SERVICE_LWH", orderServiceLwhList);
            PrincipalLogUtils.addOperationLog(ModuleNames.ORD, ModuleNames.ORD_ORDER_SERVICE_LWH, UserActions.ADD, "添加称重", dataBackup);
        }

    }

    @Override
    public void batchDelete(List<Integer> ids) {
        if (!CollectionUtils.isEmpty(ids)) {
            dao.batchDelete(getSqlName("deleteByPrimaryKey"), ids);
            //操作日志
            Map<String, Object> dataBackup = new HashMap<>();
            dataBackup.put("DELETE_ORD_ORDER_SERVICE_LWH", ids);
            PrincipalLogUtils.addOperationLog(ModuleNames.ORD, ModuleNames.ORD_ORDER_SERVICE_LWH, UserActions.DELETE, "删除称重", dataBackup);
        }

    }

    @Override
    public void deleteByOrderNo(String orderNo) {
        if (StringUtils.hasLength(orderNo)) {
            dao.delete(getSqlName("deleteByOrderNo"), orderNo);
            //操作日志
            Map<String, Object> dataBackup = new HashMap<>();
            dataBackup.put("DELETE_ORD_ORDER_SERVICE_LWH", orderNo);
            PrincipalLogUtils.addOperationLog(ModuleNames.ORD, ModuleNames.ORD_ORDER_SERVICE_LWH, UserActions.DELETE, "删除称重", dataBackup);
        }
    }

    @Override
    public void update(OrdOrderServiceLwh orderServiceLwh) {
        if (!ObjectUtils.isEmpty(orderServiceLwh)) {
            this.batchUpdate(Arrays.asList(orderServiceLwh));
        }
    }

    @Override
    public void batchUpdate(List<OrdOrderServiceLwh> list) {
        if (!CollectionUtils.isEmpty(list)) {
            dao.batchUpdate(getSqlName("updateByPrimaryKey"), list);

            //操作日志
            Map<String, Object> dataBackup = new HashMap<>();
            dataBackup.put("UPDATE_ORD_ORDER_SERVICE_LWH", list);
            PrincipalLogUtils.addOperationLog(ModuleNames.ORD, ModuleNames.ORD_ORDER_SERVICE_LWH, UserActions.UPDATE, "修改称重", dataBackup);
        }
    }

    @Override
    public OrdOrderServiceLwh findById(Integer id) {
        return null;
    }

    @Override
    public OrdOrderServiceLwh findBySubOrderNo(String subOrderNo) {
        return null;
    }

    @Override
    public List<OrdOrderServiceLwh> findBySubOrderNos(List<String> subOrderNos) {
        return null;
    }

    @Override
    public List<OrdOrderServiceLwh> findByOrderNos(List<String> orderNos) {
        List<OrdOrderServiceLwh> orderServiceLwhList = new ArrayList<>();
        if (!CollectionUtils.isEmpty(orderNos)) {
            ParamData pd = new ParamData();
            pd.put("orderNos", orderNos);
            orderServiceLwhList = dao.findForList(getSqlName("findByOrderNos"), pd, OrdOrderServiceLwh.class);
        }
        return orderServiceLwhList;
    }
}
